#!/usr/bin/env python
# -*- coding:utf- -*-
import calendar
import datetime
from datetime import datetime as dt

from conn.MyLogs import MyLogs


def get_array_day_in_params(t1, t2):
    start_datetime = dt.strptime(t1, "%Y-%m-%d")
    end_datetime = dt.strptime(t2, "%Y-%m-%d")
    delta = end_datetime - start_datetime
    diff_days = delta.days + 1
    MyLogs.logger.info(f"计算周期: {start_datetime}-{end_datetime},共计天数差{diff_days}")
    days = []
    for index_day in range(0, diff_days):
        days.append((start_datetime + datetime.timedelta(days=+index_day)).strftime("%Y-%m-%d"))
    return days


def get_array_dates_in_month(month):
    verify_date = dt.strptime(month, "%Y-%m")
    MyLogs.logger.info(f"计算周期: {verify_date}")
    last_day = calendar.monthrange(verify_date.year, verify_date.month)
    fst = datetime.datetime(verify_date.year, verify_date.month, verify_date.day).strftime("%Y-%m-%d")
    last = datetime.datetime(verify_date.year, verify_date.month, last_day[1]).strftime("%Y-%m-%d")
    return [fst, last]


if __name__ == '__main__':
    start_date = "2023-01-01"
    end_date = "2023-01-02"
    print(get_array_day_in_params(start_date, end_date))
    check_date = '2023-09'
    print(get_array_dates_in_month(check_date))
